package com.example.daojia.frametest.Activity;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.daojia.frametest.Annotation.TestAnnotation;
import com.example.daojia.frametest.Common.fileType;
import com.example.daojia.frametest.Common.text_test;
import com.example.daojia.frametest.R;

import org.w3c.dom.Text;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

@Route(path = "/test/aRouter")
public class aRouter extends AppCompatActivity {
    private static final String TAG = aRouter.class.getSimpleName() + "TAG";
    @BindView(R.id.ll_group)
    LinearLayout ll_group;
    @BindView(R.id.tv_front)
    TextView tv_front;
    int i = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_a_router);
        ButterKnife.bind(this);
        String str = getIntent().getStringExtra("data");
        if (!TextUtils.isEmpty(str)) {
            Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
        }

        String str1 = "78" + "<font Size=10>" + ".2%"
                + "</font>";
        tv_front.setText(Html.fromHtml(str1));

//        InitView(i);
//        classTest();
    }

    @Override
    protected void onResume() {
        super.onResume();
        InitView(i);
    }

    private void InitView(int index) {
        ll_group.removeAllViews();
        for (int i = 0; i < 4; i++) {
            LinearLayout layout = new LinearLayout(this);
            layout.setOrientation(LinearLayout.VERTICAL);
            layout.setGravity(Gravity.CENTER);
            LinearLayout.LayoutParams LP_MM = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1);
            layout.setLayoutParams(LP_MM);

            layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(aRouter.this, "点击事件", Toast.LENGTH_SHORT).show();
                }
            });

            for (int j = 0; j < 2; j++) {
                TextView tv = (TextView) LayoutInflater.from(aRouter.this).inflate(R.layout.text_view_item, null, false);
                tv.setText("95%");
                if (j > 0) {
                    tv.setPadding(0, 15, 0, 0);
                    if (index % 2 == 0) {
                        tv.setText("取消率");
                    } else {
                        tv.setText("接单率");
                    }
                }
                LinearLayout.LayoutParams LP_WW = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                tv.setLayoutParams(LP_WW);
                layout.addView(tv);
            }


            ll_group.addView(layout);
        }
        ImageView imageView = new ImageView(this);
        imageView.setBackgroundResource(R.drawable.picture);
        LinearLayout.LayoutParams PARA = new LinearLayout.LayoutParams(50, 50);//
        imageView.setLayoutParams(PARA);
        ll_group.addView(imageView);
        i++;
        Math.abs(i);
    }

    private void classTest() {
        fileType f = new fileType("string");

        Log.w(TAG, "onSubscribe" + " = " + f.getTypeName());

        Toast.makeText(aRouter.this, "吐司提示", Toast.LENGTH_SHORT).show();
    }

    @OnClick(R.id.add_view)
    public void addView() {
        InitView(i);

        if (text_test.class.isAnnotationPresent(TestAnnotation.class)) {
            TestAnnotation ta = text_test.class.getAnnotation(TestAnnotation.class);
            if (ta != null) {
                Toast.makeText(aRouter.this, "id: " + ta.id() + '\n' + "msg: " + ta.msg(), Toast.LENGTH_SHORT).show();
            }
        }


//        Class test = text_test.class;
//        try {
//            Constructor t = test.getConstructor(String.class);
//            text_test s = (text_test) t.newInstance("11111");
//            Toast.makeText(aRouter.this, s.getTypeName(), Toast.LENGTH_SHORT).show();
//        } catch (NoSuchMethodException e) {
//            e.printStackTrace();
//        } catch (IllegalAccessException e) {
//            e.printStackTrace();
//        } catch (InstantiationException e) {
//            e.printStackTrace();
//        } catch (InvocationTargetException e) {
//            e.printStackTrace();
//        }
    }

}
